-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload API Prep Part 1: Add db-migrate, extract config.ts, change tsoa entrypoint and use tsx in prod #33
Conversation
5128389
to
1ef7a09
Compare
Coverage Report
File Coverage
|
06ec830
to
529fec3
Compare
529fec3
to
1408127
Compare
48b84c9
to
d84ea54
Compare
cfa87d8
to
c1330de
Compare
Hey Francis, appreciate the elaborate per commit explanations in the PR description here. In future, may I suggest adding these explanations to the commit message itself? This makes it easy to review commit by commit, and will also help anyone who's looking through our history to figure out why a specific change was made. |
app.use( | ||
(err: unknown, _req: Request, _res: Response, next: NextFunction): void => { | ||
if (err instanceof ValidateError) { | ||
console.error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to consider middleware like this that automatically adds the appropriate status code to the response actually. Nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that could be cool, haven't been busy with the status codes yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good, just two questions to clarify
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
RUN npm run build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait why are we removing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no build anymore, we just run straight with tsx.
Here the commit and a bit about the rationale:
Fix production setup
The path aliases and imports without extensions were giving issues after typescript compilation, leading to a situation where devleopment works fine but production crashes.
So I chose here to just run the same way in prod as in development, namely using tsx. The alternative was doing bundling with esbuild for prod.
But I don't see an issue or big disadvantage for us with using tsx in prod and the advantage is simplicity and debuggability and least chance of discrepancies between development and prod.
@paulinevos Good point, i'll rebase to add the extra info. |
Name did not make it clear to me what this file was for
Centralized config into a file and change the tsoa entry point because otherwise the entrypoint was already importing tsoa generated code.
Centralized config into a file and change the tsoa entry point because otherwise the entrypoint was already importing tsoa generated code.
So this adds a system for database migrations.
…n there (@esbuild/darwin-arm64).
The path aliases and imports without extensions were giving issues after typescript compilation, leading to a situation where devleopment works fine but production crashes. So I chose here to just run the same way in prod as in development, namely using tsx. The alternative was doing bundling with esbuild for prod. But I don't see an issue or big disadvantage for us with using tsx in prod and the advantage is simplicity and debuggability and least chance of discrepancies between development and prod.
…run multiple instances again So we now always do db-migrate at the startup of the program. This way, we are sure that the database in the program is compatible with the queries in the program. However, these migrations are not necessarily safe to run in parallel, so in this commit I added a setup to ensure that the db-migrations are not run in parallel even when we start multiple instances of the program.
c1330de
to
a6af53e
Compare
|
||
COPY --chown=node:node ./public ./public | ||
COPY --chown=node:node ./src ./src | ||
|
||
USER node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but if you put USER node
at the top of the file, you might get rid of all the --chown=node:node
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I copied this over from the original dockedfile here, but would indeed be interesting to check if this is actually needed.
Compose file names are now more consistent. Npm script is now shorter
b452048
to
0923e6c
Compare
So this PR does some project setup:
Set up path aliases
For more readable and copy pastable imports
Auto Lint populate.ts
By prettier
Rename populate function to populateDB
Name was not clear for me
Change tsoa entryfile to app.ts and extract config.ts
Centralized config into a file and change the tsoa entry point because otherwise the entrypoint was already importing tsoa generated code.
Caused the following commit after: Fix vite unit tests
Improve logging in case of tsoa validation error
So we see more easily what went wrong when a request is not valid.
Disable write api when not in development mode
This is needed since we do not have authentication yet on the write api
Add db-migrate package with wiring, rationale and instructions
So this adds a system for database migrations.
Rebuild package-lock.json since the arm64 version of esbuild is not in there (@esbuild/darwin-arm64).
Just a package.lock update
Fix production setup
The path aliases and imports without extensions were giving issues after typescript compilation, leading to a situation where devleopment works fine but production crashes.
So I chose here to just run the same way in prod as in development, namely using tsx. The alternative was doing bundling with esbuild for prod.
But I don't see an issue or big disadvantage for us with using tsx in prod and the advantage is simplicity and debuggability and least chance of discrepancies between development and prod.
Implement using pg_try_advisory_lock for db-migrations to be able to run mulpile instances again
So we now always do db-migrate at the startup of the program. This way, we are sure that the database in the program is compatible with the queries in the program. However, these migrations are not necessarily safe to run in parallel, so in this commit I added a setup to ensure that the db-migrations are not run in parallel even when we start multiple instances of the program.